//
//  UIColor+Extension.swift
//  Weibo10
//
//  Created by male on 15/10/26.
//  Copyright © 2015年 itheima. All rights reserved.
//

import UIKit

extension UIColor {
    
    // MARK: ---------- 属性 ------------
    
    // MARK: - 默认背景颜色
    public class var backgroundColor: UIColor {
        return hexSystem16Color(Value: 0xf0f0f0)
    }
    
    // MARK: - 主色
    public class var themeColor: UIColor {
        return hexSystem16Color(Value: 0xfb4748)
    }
    
    // MARK: - 随机颜色
    public class var randomColor: UIColor {
        // 0~255
        let r = CGFloat(arc4random_uniform(256)) / 255.0
        let g = CGFloat(arc4random_uniform(256)) / 255.0
        let b = CGFloat(arc4random_uniform(256)) / 255.0
        
        return UIColor(red: r, green: g, blue: b, alpha: 1.0)
    }
    
    
    // MARK: ---------- 方法 ------------
    
    // MARK: - RGB
    public class func rgb(r: CGFloat, g: CGFloat, b: CGFloat, alpha: CGFloat = 1.0) -> UIColor {
        
        let r = r / 255.0
        let g = g / 255.0
        let b = b / 255.0
        
        return UIColor(red: r, green: g, blue: b, alpha: alpha)
    }
    
    // MARK: - 16进行转化为rgb
    public class func hexSystem16Color(Value: Int, alpha: CGFloat = 1.0) -> UIColor {
        
        let r = CGFloat((Value & 0xFF0000) >> 16) / 255.0
        let g = CGFloat((Value & 0x00FF00) >> 8)  / 255.0
        let b = CGFloat((Value & 0x0000FF) >> 0)  / 255.0
        
        return UIColor(red: r, green: g, blue: b, alpha: alpha)
    }
}
